package br.com.felix.dbm.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import br.com.felix.dbm.DatabaseObjectsFactory;
import br.com.felix.dbm.naming.ColumnClassCode;

/**
 * Helper window to display the column class codes.
 * */
public class ColumnClassCodesUi extends JFrame {

	private static final long serialVersionUID = 643950510023480145L;



	public ColumnClassCodesUi() throws HeadlessException {
		super("Class Codes");
		setAlwaysOnTop(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(new Dimension(200, 300));

		Color lightYellow = new Color(255, 255, 200);
		setBackground(lightYellow);

		List<ColumnClassCode> lst = DatabaseObjectsFactory.getColumnClassCodes().getColumnClassCodeList();
		String[][] data = new String[lst.size()][2];
		String[] columnNames = new String[] { "Code", "Name" };
		int i = 0;
		for (ColumnClassCode ccc : lst) {
			data[i][0] = ccc.getCode();
			data[i][1] = ccc.getName();
			i++;
		}
		DefaultTableModel dtm = new DefaultTableModel(data, columnNames);
		JTable tblCodes = new JTable(dtm);
		tblCodes.setBackground(lightYellow);
		tblCodes.setEnabled(false);

		JScrollPane jsp = new JScrollPane(tblCodes);
		add(jsp);
	}

}
